home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Software Contest 3 / FM Towns Software Contest 3.iso / exp / astral / a1 / game / source / wire3d_a.asm < prev    next >
Assembly Source File  |  1994-01-07  |  9KB  |  681 lines

  1. ;============================================================================
  2. ;
  3. ;    Wireflame アセンブラ版
  4. ;
  5. ;============================================================================
  6.  
  7. .386p
  8.  
  9. ;---    各種宣言
  10.  
  11. extrn    sin_data:dword,cos_data:dword,line:near
  12. public    wire3d
  13.  
  14. arg_angle    equ    ss:[ebp]+4+4
  15. arg_offset    equ    ss:[ebp]+4+8
  16. arg_obj        equ    ss:[ebp]+4+12
  17. arg_page    equ    ss:[ebp]+4+16
  18.  
  19. sight_angle    equ    100h
  20.  
  21. wire_object    struc
  22.  
  23. color        dd    ?
  24. dummy        dd    ?
  25. point_num    dd    ?
  26. point        dd    128*3 dup(?)
  27. line_num    dd    ?
  28. m_line        dd    128*2 dup(?)
  29.  
  30. wire_object    ends
  31.  
  32. call_line    macro
  33.  
  34. ;    push    eax
  35. ;    push    ecx
  36. ;    push    edx
  37.  
  38.     push    arg_page
  39.     mov    eax,arg_obj
  40.     push    [eax].color
  41.     push    y2
  42.     push    x2
  43.     push    y1
  44.     push    x1
  45.  
  46.     call    line
  47.  
  48.     add    esp,6*4
  49.  
  50. ;    pop    edx
  51. ;    pop    ecx
  52. ;    pop    eax
  53.  
  54.         endm
  55.  
  56. break_point    macro    reg
  57.  
  58.     mov    eax,reg
  59.     jmp    exit
  60.  
  61.         endm
  62.  
  63. DSEG    segment    dword    'DATA'
  64.     assume    cs:CSEG,ds:DSEG
  65.  
  66. ;---    プログラム用ワークエリア
  67.  
  68.     align    4
  69.  
  70. i        dd    ?        ;i
  71. point_work    dd    192 dup(?)    ;point_work[192]
  72. x1        dd    0        ;x1,y1,x2,y2
  73. y1        dd    0
  74. x2        dd    255
  75. y2        dd    255
  76. clip_work2    dd    ?        ;w
  77. xx        dd    ?        ;xx
  78. yy        dd    ?        ;yy
  79. point_w        dd    12 dup(?)    ;point_w[4][3]([y][x*4]+point_w)
  80. z_w        dd    ?        ;z_w
  81. pass        dd    192 dup(?)    ;pass[192]
  82.  
  83. DSEG    ends
  84.  
  85. CSEG    segment    dword    'CODE'
  86.     assume    cs:CSEG,ds:DSEG
  87.  
  88. ;----------------------------------------------------------------------------
  89. ;    void wire3d(unsigned char *angle,int *offset,WIRE_OBJECT *obj,int pag
  90. ;     e);
  91. ;----------------------------------------------------------------------------
  92.  
  93.     db    'wire3d',6
  94.  
  95.     align    4
  96.  
  97. wire3d    proc    near
  98.  
  99.     push    ebp
  100.     mov    ebp,esp
  101.     push    edi
  102.     push    esi
  103.     push    ebx
  104.  
  105.     mov    edi,arg_obj        ;edi=obj
  106.  
  107. ;---    回転,オフセット付加,透視変換
  108.  
  109.     mov    eax,[edi].point_num    ;ループカウンタをセット
  110.     lea    ebx,[eax+eax*2]        ;ebx=Loop Counter
  111.  
  112.     align    4
  113.  
  114. roll_loop:
  115.  
  116.     sub    ebx,3            ;ebx-=3
  117.  
  118. ;---    Y軸の回転
  119.  
  120.     mov    eax,arg_angle
  121.     mov    ecx,0
  122.     mov    cl,ds:[eax]+1
  123.  
  124. ; point_w[2][0]=(point_w[1][0] * cos_data[angle[1]] -
  125. ;  point_w[1][2] * sin_data[angle[1]])>>16;
  126.  
  127.     mov    eax,ds:[edi].point[ebx*4]+0
  128.     imul    eax,ds:cos_data[ecx*4]
  129.     mov    edx,ds:[edi].point[ebx*4]+8
  130.     imul    edx,ds:sin_data[ecx*4]
  131.     sub    eax,edx
  132.     sar    eax,7
  133.     mov    point_w+1*12+0,eax
  134.  
  135. ; point_w[2][2]=(point_w[1][0] * sin_data[angle[1]] +
  136. ;  point_w[1][2] * cos_data[angle[1]])>>16;
  137.  
  138.     mov    eax,ds:[edi].point[ebx*4]+0
  139.     imul    eax,ds:sin_data[ecx*4]
  140.     mov    edx,ds:[edi].point[ebx*4]+8
  141.     imul    edx,ds:cos_data[ecx*4]
  142.     add    eax,edx
  143.     sar    eax,7
  144.     mov    point_w+1*12+8,eax
  145.  
  146. ;---    X軸の回転
  147.  
  148.     mov    eax,arg_angle        ;ecxにangle[0]を入れる
  149.     mov    ecx,0
  150.     mov    cl,ds:[eax]
  151.  
  152. ; point_w[1][1]=( obj->point[i+1] * cos_data[angle[0]] +
  153. ;  obj->point[i+2] * sin_data[angle[0]] )>>16;
  154.  
  155.     mov    eax,ds:[edi].point[ebx*4]+4
  156.     imul    eax,ds:cos_data[ecx*4]
  157.     mov    edx,point_w+12*1+8
  158.     imul    edx,ds:sin_data[ecx*4]
  159.     add    eax,edx
  160.     sar    eax,7
  161.     mov    point_w+2*12+4,eax
  162.  
  163. ; point_w[1][2]=(-obj->point[i+1] * sin_data[angle[0]] +
  164. ;  obj->point[i+2] * cos_data[angle[0]] )>>16;
  165.  
  166.     mov    eax,ds:[edi].point[ebx*4]+4
  167.     imul    eax,ds:sin_data[ecx*4]
  168.     mov    edx,point_w+12*1+8
  169.     imul    edx,ds:cos_data[ecx*4]
  170.     sub    edx,eax
  171.     sar    edx,7
  172.     mov    eax,arg_offset
  173.     add    edx,ds:[eax]+8
  174.     mov    point_w+3*12+8,edx
  175.  
  176. ;---    Z軸の回転
  177.  
  178.     mov    eax,arg_angle
  179.     mov    ecx,0
  180.     mov    cl,ds:[eax]+2
  181.  
  182. ; point_w[3][0]=(( point_w[2][0] * cos_data[angle[2]] +
  183. ;  point_w[2][1] * sin_data[angle[2]])>>16)+offset[0];
  184.  
  185.     mov    eax,point_w+1*12+0
  186.     imul    eax,cos_data[ecx*4]
  187.     mov    edx,point_w+2*12+4
  188.     imul    edx,sin_data[ecx*4]
  189.     add    eax,edx
  190.     sar    eax,7
  191.     mov    edx,arg_offset
  192.     add    eax,ds:[edx]+0
  193.     mov    point_w+3*12+0,eax
  194.  
  195. ; point_w[3][1]=((-point_w[2][0] * sin_data[angle[2]] +
  196. ;  point_w[2][1] * cos_data[angle[2]])>>16)+offset[1];
  197.  
  198.     mov    eax,point_w+1*12+0
  199.     imul    eax,sin_data[ecx*4]
  200.     mov    edx,point_w+2*12+4
  201.     imul    edx,cos_data[ecx*4]
  202.     sub    edx,eax
  203.     sar    edx,7
  204.     mov    eax,arg_offset
  205.     add    edx,ds:[eax]+4
  206.     mov    point_w+3*12+4,edx
  207.  
  208. ;---    透視変換
  209.  
  210. ; z_w=point_w[3][2]*SIGHT_ANGLE+0x10000;
  211.  
  212.     mov    eax,point_w+3*12+8
  213.     add    eax,100h
  214.     mov    ecx,eax
  215.  
  216. ; if(z_w<=0){
  217. ;    pass[i]=1;
  218. ;    continue;
  219. ; }
  220.  
  221.     cmp    ecx,0
  222.     jnle    roll_next1
  223.     mov    pass[ebx*4],1
  224.     cmp    ebx,0
  225.     jnz    roll_loop
  226.     jmp    roll_loop_break
  227.  
  228. ; point_work[i+0]=((point_w[3][0]<<16)/z_w)+128;
  229.  
  230.     align    4
  231.  
  232. roll_next1:
  233.     mov    pass[ebx*4],0
  234.  
  235.     mov    eax,point_w+3*12+0
  236.     sal    eax,8
  237.     cdq
  238.     idiv    ecx
  239.     add    eax,128
  240.     mov    point_work[ebx*4]+0,eax
  241.  
  242. ; point_work[i+1]=((point_w[3][1]<<16)/z_w)+128;
  243.  
  244.     mov    eax,point_w+3*12+4
  245.     neg    eax
  246.     sal    eax,8
  247.     cdq
  248.     idiv    ecx
  249.     add    eax,120
  250.     mov    point_work[ebx*4]+4,eax
  251.  
  252. ;---    ループおしまい
  253.  
  254. roll_loop_end:
  255.  
  256.     cmp    ebx,0
  257.     jnz    roll_loop
  258.  
  259. roll_loop_break:
  260.  
  261. ;---    クリッピング,描画
  262.  
  263.     mov    eax,[edi].line_num
  264.     lea    ebx,[eax*2]
  265.  
  266.     align    4
  267.  
  268. draw_loop:
  269.  
  270.     sub    ebx,2
  271.  
  272.     mov    edi,arg_obj
  273.  
  274. ; if(pass[obj->line[i]*3]==1 || pass[obj->line[i+1]*3]==1)continue;
  275.  
  276. ; x1=point_work[obj->line[i]*3];
  277.  
  278.     mov    eax,ds:[edi].m_line[ebx*4]    ;obj->line[i]
  279.     lea    edx,[eax+eax*2]        ;*3
  280.     cmp    pass[edx*4],1
  281.     jz    continue
  282.     mov    eax,point_work[edx*4]
  283.     mov    x1,eax
  284.  
  285. ; y1=point_work[obj->line[i]*3+1];
  286.  
  287.     mov    eax,point_work[edx*4]+4        ;+1
  288.     mov    y1,eax
  289.  
  290. ; x2=point_work[obj->line[i+1]*3];
  291.  
  292.     mov    eax,ds:[edi].m_line[ebx*4]+4
  293.     lea    edx,[eax+eax*2]
  294.     cmp    pass[edx*4],1
  295.     jz    continue
  296.     mov    eax,point_work[edx*4]
  297.     mov    x2,eax
  298.  
  299. ; y2=point_work[obj->line[i+1]*3+1];
  300.  
  301.     mov    eax,point_work[edx*4]+4
  302.     mov    y2,eax
  303.  
  304. ; if(x1>0 && x1<255 && y1>0 && y1<255 &&
  305. ;  x2>0 && x2<255 && y2>0 && y2<255){
  306. ;     line(x1,y1,x2,y2,obj->color,page);
  307. ;     continue;
  308. ; }
  309.  
  310.     mov    eax,x1
  311.     or    eax,y1
  312.     or    eax,x2
  313.     or    eax,y2
  314.     and    eax,0ffffff00h
  315.     jnz    next1
  316.  
  317.     call_line
  318.  
  319.     cmp    ebx,0
  320.     jnz    draw_loop
  321.     jmp    draw_loop_break
  322.  
  323.     align    4
  324.  
  325. next1:
  326.  
  327. ;    jmp    continue
  328.  
  329.  
  330. ; if( (x1<0 && x2<0) || (x1>255 && x2>255) ||
  331. ;  (y1<0 && y2<0) || (y1>255 && y2>255) ){
  332. ;     continue;
  333. ; }
  334.  
  335.     mov    eax,x1
  336.     and    eax,x2
  337.     and    eax,80000000h
  338.     jnz    continue
  339.  
  340.     cmp    x1,256
  341.     jb    next2
  342.  
  343.     cmp    x2,256
  344.     jnb    continue
  345.  
  346.     align    4
  347.  
  348. next2:
  349.     mov    eax,y1
  350.     and    eax,y2
  351.     and    eax,80000000h
  352.     jnz    continue
  353.  
  354.     cmp    y1,256
  355.     jb    next3
  356.  
  357.     cmp    y2,256
  358.     jnb    continue
  359.  
  360.     align    4
  361.  
  362. next3:
  363.  
  364. ;    xx..ecx
  365. ;    yy..esi
  366.  
  367. ; if(x2<0){
  368. ;     xx=1;
  369. ; }
  370.  
  371.     mov    ecx,x2
  372.     cmp    ecx,80000000h
  373.     jb    next4
  374.     mov    ecx,1
  375.     jmp    next5
  376.  
  377. ; else{
  378. ;     if(x2>255){
  379. ;         xx=255;
  380. ;     }
  381. ;     else{
  382. ;         xx=x2;
  383. ;     }
  384. ; }
  385.  
  386.     align    4
  387.  
  388. next4:
  389.     cmp    ecx,256
  390.     jb    next5
  391.     mov    ecx,255
  392.  
  393.     align    4
  394.  
  395. next5:
  396.  
  397. ; if(x2==x1){
  398. ;     yy=y2;
  399. ; }
  400.  
  401.     mov    eax,x1
  402.     cmp    eax,x2
  403.     jnz    next6
  404.     mov    esi,y2
  405.     jmp    next7
  406.  
  407. ; else{
  408. ;     yy=y2-(y2-y1)*(x2-xx)/(x2-x1);
  409. ; }
  410.  
  411.     align    4
  412.  
  413. next6:
  414.     mov    eax,y2
  415.     sub    eax,y1
  416.     mov    edi,x2
  417.     sub    edi,ecx
  418.     imul    eax,edi
  419.     cdq
  420.     mov    edi,x2
  421.     sub    edi,x1
  422.     idiv    edi
  423.     mov    edi,y2
  424.     sub    edi,eax
  425.     mov    esi,edi
  426.  
  427.     align    4
  428.  
  429. next7:
  430.  
  431. ; if(yy<0){
  432. ;     yy=0;
  433. ; }
  434.  
  435.     cmp    esi,80000000h
  436.     jb    next8
  437.     mov    esi,0
  438.     jmp    next9
  439.  
  440.     align    4
  441.  
  442. next8:
  443.  
  444. ; else{
  445. ;     if(yy>255){
  446. ;         yy=255;
  447. ;     }
  448. ;     else{
  449. ;         goto EXIT1;
  450. ;     }
  451. ; }
  452.  
  453.     cmp    esi,256
  454.     jb    EXIT_clip1
  455.     mov    esi,255
  456.  
  457.     align    4
  458.  
  459. next9:
  460.  
  461. ; if(y2==y1){
  462. ;     xx=x2;
  463. ; }
  464. ; else{
  465. ;     xx=x2-(x2-x1)*(y2-yy)/(y2-y1);
  466. ; }
  467.  
  468.     mov    eax,y1
  469.     cmp    eax,y2
  470.     jnz    next10
  471.     mov    ecx,x2
  472.     jmp    EXIT_clip1
  473.  
  474.     align    4
  475.  
  476. next10:
  477.     mov    eax,x2
  478.     sub    eax,x1
  479.     mov    edi,y2
  480.     sub    edi,esi
  481.     imul    eax,edi
  482.     cdq
  483.     mov    edi,y2
  484.     sub    edi,y1
  485.     idiv    edi
  486.     mov    edi,x2
  487.     sub    edi,eax
  488.     mov    ecx,edi
  489.  
  490.     align    4
  491.  
  492. EXIT_clip1:
  493.  
  494. ; EXIT1:
  495. ; x2=xx;
  496. ; y2=yy;
  497.  
  498.     mov    x2,ecx
  499.     mov    y2,esi
  500.  
  501. ; swap x1,x2;
  502. ; swap y1,y2;
  503.  
  504.     mov    eax,x1
  505.     mov    edx,x2
  506.     mov    x2,eax
  507.     mov    x1,edx
  508.  
  509.     mov    eax,y1
  510.     mov    edx,y2
  511.     mov    y2,eax
  512.     mov    y1,edx
  513.  
  514. next23:
  515.  
  516. ;    xx..ecx
  517. ;    yy..esi
  518.  
  519. ; if(x2<0){
  520. ;     xx=1;
  521. ; }
  522.  
  523.     mov    ecx,x2
  524.     cmp    ecx,80000000h
  525.     jb    next24
  526.     mov    ecx,1
  527.     jmp    next25
  528.  
  529. ; else{
  530. ;     if(x2>255){
  531. ;         xx=255;
  532. ;     }
  533. ;     else{
  534. ;         xx=x2;
  535. ;     }
  536. ; }
  537.  
  538.     align    4
  539.  
  540. next24:
  541.     cmp    ecx,256
  542.     jb    next25
  543.     mov    ecx,255
  544.  
  545.     align    4
  546.  
  547. next25:
  548.  
  549. ; if(x2==x1){
  550. ;     yy=y2;
  551. ; }
  552.  
  553.     mov    eax,x1
  554.     cmp    eax,x2
  555.     jnz    next26
  556.     mov    esi,y2
  557.     jmp    next27
  558.  
  559. ; else{
  560. ;     yy=y2-(y2-y1)*(x2-xx)/(x2-x1);
  561. ; }
  562.  
  563.     align    4
  564.  
  565. next26:
  566.     mov    eax,y2
  567.     sub    eax,y1
  568.     mov    edi,x2
  569.     sub    edi,ecx
  570.     imul    eax,edi
  571.     cdq
  572.     mov    edi,x2
  573.     sub    edi,x1
  574.     idiv    edi
  575.     mov    edi,y2
  576.     sub    edi,eax
  577.     mov    esi,edi
  578.  
  579.     align    4
  580.  
  581. next27:
  582.  
  583. ; if(yy<0){
  584. ;     yy=0;
  585. ; }
  586.  
  587.     cmp    esi,80000000h
  588.     jb    next28
  589.     mov    esi,0
  590.     jmp    next29
  591.  
  592.     align    4
  593.  
  594. next28:
  595.  
  596. ; else{
  597. ;     if(yy>255){
  598. ;         yy=255;
  599. ;     }
  600. ;     else{
  601. ;         goto EXIT1;
  602. ;     }
  603. ; }
  604.  
  605.     cmp    esi,256
  606.     jb    EXIT_clip2
  607.     mov    esi,255
  608.  
  609.     align    4
  610.  
  611. next29:
  612.  
  613. ; if(y2==y1){
  614. ;     xx=x2;
  615. ; }
  616. ; else{
  617. ;     xx=x2-(x2-x1)*(y2-yy)/(y2-y1);
  618. ; }
  619.  
  620.     mov    eax,y1
  621.     cmp    eax,y2
  622.     jnz    next210
  623.     mov    ecx,x2
  624.     jmp    EXIT_clip2
  625.  
  626.     align    4
  627.  
  628. next210:
  629.     mov    eax,x2
  630.     sub    eax,x1
  631.     mov    edi,y2
  632.     sub    edi,esi
  633.     imul    eax,edi
  634.     cdq
  635.     mov    edi,y2
  636.     sub    edi,y1
  637.     idiv    edi
  638.     mov    edi,x2
  639.     sub    edi,eax
  640.     mov    ecx,edi
  641.  
  642.     align    4
  643.  
  644. EXIT_clip2:
  645.  
  646. ; EXIT1:
  647. ; x2=xx;
  648. ; y2=yy;
  649.  
  650.     mov    x2,ecx
  651.     mov    y2,esi
  652.  
  653.     call_line
  654.  
  655. ;---    ループおしまい
  656.  
  657.     align    4
  658.  
  659. continue:
  660.     cmp    ebx,0
  661.     jnz    draw_loop
  662.  
  663. draw_loop_break:
  664.  
  665. ;---    Return
  666.  
  667. exit:
  668.     pop    ebx
  669.     pop    esi
  670.     pop    edi
  671.     pop    ebp
  672.  
  673.     ret
  674.  
  675. wire3d    endp
  676.  
  677. CSEG    ends
  678.  
  679.     end
  680.  
  681.